package team18.yuejian.Model;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import team18.yuejian.RetrofitCallback;
import team18.yuejian.RetrofitListener;

public class RetrofitModel {
    private String Url = "http://172.19.70.213:88/yuejian/public";
    private String BaseUrl = Url+"/index.php/Api/";
    private String PicUrl =  Url+"/static/";


    protected RetrofitCallBuilder retrofitCallBuilder;

    public String getBaseUrl() {
        return BaseUrl;
    }

    public String getPicUrl() {
        return PicUrl;
    }

    public RetrofitModel(){
        retrofitCallBuilder = RetrofitCallBuilder.getInstance()
                .baseUrl(BaseUrl);
    }

    public <T> void bindCallback(Call<T> call, final RetrofitListener listener , final Response<T> response , final int flag) {
        Callback<T> callback = new Callback<T>() {
            @Override
            public void onResponse(Call<T> call, Response<T> response) {
                listener.onSuccess(response.body(),flag);
            }

            @Override
            public void onFailure(Call<T> call, Throwable t) {
                String msg1 = t.toString();
                listener.onFail(msg1);
            }
        };
        call.enqueue(callback);
    }


}
